package com.dlc.longweisheng.chongdianxian.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;


import com.dlc.longweisheng.chongdianxian.BuildConfig;
import com.dlc.longweisheng.chongdianxian.R;
import com.dlc.longweisheng.chongdianxian.pub.Constant;

import cn.dlc.commonlibrary.utils.ToastUtil;

/**
 * Created by Administrator on 2018\12\26 0026.
 */

public class PasswordDialog implements View.OnClickListener {
    private Activity activity;
    private final View view;
    private Dialog dialog;
    EditText etPass;

    public PasswordDialog(Activity activity) {
        this.activity = activity;
        view = LayoutInflater.from(activity).inflate(R.layout.dialog_password, null);

        etPass = view.findViewById(R.id.et_pass);
        if (BuildConfig.DEBUG) {
            etPass.setText(Constant.DEFAULT_CHECK_PASSWORD);
        }
        view.findViewById(R.id.ll_dialog).setOnClickListener(this);

        dialog = new Dialog(activity, R.style.my_style_dialog);
        dialog.setContentView(view);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);


    }

    public boolean isPasswordRight() {
        String pass = etPass.getText().toString().trim();
        if (!pass.equals(Constant.DEFAULT_CHECK_PASSWORD)) {
            ToastUtil.showOne(activity, "密码不正确");
            return false;
        }
        etPass.setText("");
        return true;
    }

    public void setPostClickListener(View.OnClickListener clickListener) {
        view.findViewById(R.id.bt_post).setOnClickListener(clickListener);
    }

    public void show() {
        dialog.show();
    }

    public void dismiss() {
        dialog.dismiss();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_dialog:
                dismiss();
                break;
        }
    }


}
